package org.infodavid.common.model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.infodavid.common.IBuilder;
import org.infodavid.common.ejb.UserConnectionBean;

/**
 * The Class UserConnectionTest.
 */
public class UserConnectionTest extends AbstractBeanTest<IUserConnection> {

	/** The user test. */
	private final UserTest userTest = new UserTest(this);

	/**
	 * Instantiates a new test.
	 * @param mainTest the main test
	 */
	@SuppressWarnings("rawtypes")
	public UserConnectionTest(final AbstractBeanTest mainTest) {
		super(mainTest);
	}

	/**
	 * Instantiates a new user test.
	 */
	public UserConnectionTest() {
		super();
	}

	/**
	 * Populate.
	 * @param count the count
	 * @return the collection< test data>
	 * @throws Exception the exception
	 */
	@Override
	protected List<IUserConnection> doCreate(final int count) throws Exception {
		final IBuilder<IUserConnection> builder =
		    ModelFactory.getInstance().getBuilder(IUserConnection.class);
		final Iterator<IUser> users = userTest.populate(count * 2).iterator();
		final List<IUserConnection> items = new ArrayList<IUserConnection>(count);
		IUserConnection item;
		long key;

		for (int i = 0; i < count; i++) {
			item = builder.create();
			key = System.nanoTime();

			item.setArchived(false);
			item.setComment("comment-" + key);
			item.setInitiator(users.next());
			item.setRecipient(users.next());

			items.add(item);
		}

		return items;
	}

	/**
	 * See super class or interface. (non-Javadoc)
	 * @see org.infodavid.common.model.AbstractBeanTest#getEntityClass()
	 */
	@Override
	public Class<UserConnectionBean> getEntityClass() {
		return UserConnectionBean.class;
	}

	/**
	 * See super class or interface. (non-Javadoc)
	 * @see org.infodavid.common.model.AbstractBeanTest#getEntityName()
	 */
	@Override
	public String getEntityName() {
		return IUserConnection.class.getSimpleName();
	}
}
